/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sunspotworld.hardware;

import com.sun.spot.peripheral.IDriver;
import com.sun.spot.peripheral.Spot;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.ITriColorLED;
import com.sun.spot.sensorboard.peripheral.LEDColor;

/**
 *
 * @author me
 */
public class LEDManager implements IDriver {
    private ITriColorLED[] leds = EDemoBoard.getInstance().getLEDs();
    private boolean [] isOn = new boolean[8];
    private boolean shuttingDown=false;
    private static LEDManager manager = new LEDManager();
    
    private LEDManager() {
        //Spot.getInstance().getDriverRegistry().add(this);
    }
    
    public static LEDManager getInstance() {
        return manager;
    }
    
    public void setColor(int index, LEDColor color) {
        leds[index].setColor(color);
    }
    
    public void clearLEDs() {
        for (int i=0; i<8; i++) {
            isOn[i]=false;
            leds[i].setOff();
        }
    }
    
    public void toggleLED(int i) {
        if (i>=0 && i<8) {
            isOn[i] = !isOn[i];
            leds[i].setOn(isOn[i]);
        }
    }

    public void turnOnLED(int i) {
        if (i>=0 && i<8) {
            isOn[i] = true;
            leds[i].setOn(isOn[i]);
        }
    }

    public void turnOffLED(int i) {
        if (i>=0 && i<8) {
            isOn[i] = false;
            leds[i].setOn(isOn[i]);
        }
    }

    public String getDriverName() {
        return "LEDManager";
    }

    public boolean tearDown() {
        clearLEDs();
        return true;
    }

    public void setUp() {
    }

    public void shutDown() {
    }
}
